<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    {
        StringBuilder builder = new StringBuilder();
        builder.AppendLine("============EXCEPTION OCCURED============");
        builder.AppendFormat("Date UTC:        {0}\r\n", DateTime.UtcNow);

        try
        {
            builder.AppendFormat("Handler:         {0}\r\n", HttpContext.Current.Request.PhysicalPath);
            builder.AppendFormat("Raw URL:         {0}\r\n", HttpContext.Current.Request.RawUrl);
            builder.AppendFormat("Is Authed:       {0}\r\n", HttpContext.Current.User.Identity.IsAuthenticated);
            builder.AppendFormat("Has User:        {0}\r\n", Decav.Gatsb.Application.GatsbApplication.Current.UserPresent);
            if (Decav.Gatsb.Application.GatsbApplication.Current.UserPresent)
            {
                builder.AppendFormat("User ID:         {0}\r\n", Decav.Gatsb.Application.GatsbApplication.Current.CurrentUser.Id);
            }
        }
        catch { /* Swallow Exception */ }

        foreach (Exception ex in HttpContext.Current.AllErrors)
        {
            builder.AppendLine("=============EXCEPTION============");
            string str = Decav.Diagnostics.DecavDiagnostics.GetExceptionDetails(ex);
            builder.AppendLine(str);
            builder.AppendLine("\r\n\r\n\r\n");
        }

        Decav.Gatsb.Diagnostics.GatsbDiagnostics.WriteLogEntry(builder.ToString(), System.Diagnostics.EventLogEntryType.Error);
    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
